package com.hxzy.projectssmplus.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hxzy.projectssmplus.dto.RentApartmentDTO;
import com.hxzy.projectssmplus.entity.RentApartment;
import com.hxzy.projectssmplus.service.RentApartmentService;

import com.hxzy.projectssmplus.vo.AjaxResult;
import com.hxzy.projectssmplus.vo.AjaxTableInfo;
import com.hxzy.projectssmplus.vo.RentApartmentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class RentApartmentController extends BaseController{

    @Autowired
    private RentApartmentService rentApartmentService;


    @GetMapping(value = "/rent/search")
    public AjaxTableInfo search(RentApartmentDTO rentApartmentDTO){
        IPage<RentApartmentVO> rentApartmentVOIPage = this.rentApartmentService.rentSearch(super.startPage(), rentApartmentDTO);
        return super.getTableInfo(rentApartmentVOIPage);
    }

    @PostMapping(value = "/rent/add")
    public AjaxResult rentAdd(RentApartment rentApartment){
        boolean save = this.rentApartmentService.save(rentApartment);
        if (save){
            return AjaxResult.success("新增成功");
        }else {
            return AjaxResult.error("新增失败");
        }
    }

    @PostMapping(value = "/rent/edit")
    public AjaxResult rentUpdate(RentApartment rentApartment){
        boolean updateById = this.rentApartmentService.updateById(rentApartment);
        if (updateById){
            return AjaxResult.success("修改成功");
        }else {
            return AjaxResult.error("修改失败");
        }
    }
}
